package com.controller;

import com.bean.MenuUrl;
import com.service.MenuUrlService;
import org.python.antlr.op.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * Created by Ming on 2016/9/26.
 */

@Controller
@RequestMapping("menuurl")
public class MenuUrlController {
    @Autowired
    private MenuUrlService menuUrlService;

    @RequestMapping("/delMenuMsgById")
    //删除对应id菜单信息
    public String delMenuMsgById(HttpServletRequest request){
        Long id = Long.parseLong(request.getParameter("id"));
        menuUrlService.delMenuMsgById(id);
        return "redirect:/submenu/menu-list.do";
    }


    @RequestMapping("/updateMenuMsgById")
    //修改指定id菜单信息
    public String updateMenuMsgById(HttpServletRequest request){
        String jspName = request.getParameter("jspName");
        Integer level = Integer.parseInt(request.getParameter("level"));
        String jspUrl = request.getParameter("jspUrl");
        Long parentId = Long.parseLong(request.getParameter("parentId"));
        String icon = request.getParameter("icon");
        Long id = Long.parseLong(request.getParameter("id"));

        MenuUrl menuUrl = new MenuUrl();
        menuUrl.setId(id);
        menuUrl.setIcon(icon);
        menuUrl.setJspName(jspName);
        menuUrl.setJspUrl(jspUrl);
        menuUrl.setLevel(level);
        menuUrl.setParentId(parentId);

        int i = menuUrlService.updateMenuMsgById(menuUrl);
        return "redirect:/submenu/menu-list.do";
    }


    @RequestMapping("/insertMenuMsg")
    //添加新的菜单信息
    public String insertMenuMsg(HttpServletRequest request){
        String jspName = request.getParameter("jspName");
        Integer level = Integer.parseInt(request.getParameter("level"));
        String jspUrl = request.getParameter("jspUrl");
        Long parentId = Long.parseLong(request.getParameter("parentId"));
        String icon = request.getParameter("icon");

        MenuUrl menuUrl = new MenuUrl();
        menuUrl.setIcon(icon);
        menuUrl.setJspName(jspName);
        menuUrl.setJspUrl(jspUrl);
        menuUrl.setLevel(level);
        menuUrl.setParentId(parentId);

        int i = menuUrlService.insertMenuMsg(menuUrl);


        return "redirect:/submenu/menu-list.do";
    }




}
